package com.ymatou.iapi.prodstock.testcase;

import com.ymatou.iapi.liveseller.parameter.ActivityProductDto;
import com.ymatou.iapi.liveseller.parameter.CreateLiveActivityBean;
import com.ymatou.iapi.liveseller.parameter.CreateSellerLiveBean;
import com.ymatou.iapi.liveseller.parameter.LiveActivityDto;
import com.ymatou.iapi.prodstock.parameter.AllocateProductActivityStockBean;
import com.ymatou.iapi.prodstock.parameter.AuditProductActivityStockBean;
import com.ymatou.iapi.prodstock.parameter.ModifyResult;
import com.ymatou.iapi.prodstock.parameter.ProductActivityStockDto;
import com.ymatou.iapi.prodstock.service.AllocateProductActivityStockCall;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.mq.admin.parameter.MessageListBean;
import com.ymatou.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.database.RedisDriver;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.business.service.MqQueryCallService;
import com.ymttest.business.service.ProdStockCallService;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.business.service.ProductStockCallService;
import com.ymttest.database.model.LiveRoom;
import com.ymttest.database.model.YmtCatalogsI;
import com.ymttest.database.model.YmtProductActivityStock;
import com.ymttest.database.sqlwapper.LiveRoomWapper;
import com.ymttest.database.sqlwapper.YmtCatalogsIWapper;
import com.ymttest.database.sqlwapper.YmtProductActivityStockWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.YMTDateUtil;
import org.junit.*;
import org.junit.experimental.categories.Category;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
*调拨活动库存
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_AllocateProductActivityStock{
	private static AllocateProductActivityStockBean allocateproductactivitystockBean;
	private static AllocateProductActivityStockCall allocateproductactivitystockCall;
	private static int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
	private static ArrayList<ProductActivityStockDto> ProductActivityStock;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("调拨活动库存");
	}

	@Before
	public void caseUp() {
		allocateproductactivitystockBean=new AllocateProductActivityStockBean();
		allocateproductactivitystockCall=new AllocateProductActivityStockCall();
		ProductActivityStock = new ArrayList<ProductActivityStockDto>();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(allocateproductactivitystockCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AllocateProductActivityStock_001() {
		Logger.start(true,"活动商品，某个未参加活动规格，调拨活动库存");
		try {
			/**
			 * 运行通过，日志记录
			 */
			//创建商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			addpro.getProduct().getCatalogList().remove(0);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			//获取商品ID，单规格
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,"10");
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);
			//活动开始
			String BeginTime = YMTDateUtil.getBeforeOrNextDay(-1, YMTDateUtil.YMDTHMS_STRING);
			allocateproductactivitystockBean.setBeginTime(BeginTime);
			String EndTime = YMTDateUtil.getBeforeOrNextDay(1, YMTDateUtil.YMDTHMS_STRING);
			allocateproductactivitystockBean.setEndTime(EndTime);
			allocateproductactivitystockBean.setActivityID(activityId);
			allocateproductactivitystockBean.setProductActivityId(Integer.valueOf(aids.get(0)));
			allocateproductactivitystockBean.setUserID(sellerId);
			allocateproductactivitystockBean.setProductID(productId);
			allocateproductactivitystockBean.setStoreType(-1);
			
			ProductActivityStockDto productActivityStockDto = new ProductActivityStockDto();
			productActivityStockDto.setActivityPrice(new BigDecimal(10));
			productActivityStockDto.setCatalogId(catalogs.get(0));
			productActivityStockDto.setSku(null);
			productActivityStockDto.setStock(300);
			ProductActivityStock.add(productActivityStockDto);
			allocateproductactivitystockBean.setFBXCatalogLockList(ProductActivityStock);
			
			allocateproductactivitystockCall.setData(allocateproductactivitystockBean);
			allocateproductactivitystockCall.callService();
			
			String Code = allocateproductactivitystockCall.getString("Code")	;
			Logger.verifyEquals("200",Code,"验证Code");
			allocateproductactivitystockCall.getModifyResultList().forEach(pp->{
				Logger.verifyEquals(productId, pp.getProductId(), "验证商品编号");
				//Logger.verifyEquals(catalog0, pp.getCatalogId(), "验证规格编号");
				Logger.verifyEquals(activityId, pp.getActivityID(), "验证活动编号");
				Logger.verifyEquals(aids.get(0), pp.getProductActivityId().toString(), "验证商品在活动中编号");
			});
			
			//商品规格库存
			//Integer inum = new YmtCatalogsIWapper().selectCatalogsByCatalogId(catalog0).getiNum();
			//Logger.verifyEquals(catalogNum,inum,"验证商品库存表与预期期望一致");
			
			//发送同步指令SyncActivityProduct
			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AllocateProductActivityStock_002() {
		Logger.start(true,"活动商品规格，调拨活动库存，扣规格库存");
		/**
		 * 调拨活动库存是在原来的库存上直接加传入的值
		 */
		try {
			//创建商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,"10");
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);
			Logger.debug("活动库存1:"+FormatUtil.beanToGSONString(new YmtProductActivityStockWapper().selectByCatalogId(catalogs.get(0))));
			Integer istocknum = new YmtProductActivityStockWapper().selectByCatalogId(catalogs.get(0)).getIstocknum();
			//活动未开始
			String BeginTime = YMTDateUtil.getBeforeOrNextDay(-1, YMTDateUtil.YMDTHMS_STRING);
			allocateproductactivitystockBean.setBeginTime(BeginTime);
			String EndTime = YMTDateUtil.getBeforeOrNextDay(1, YMTDateUtil.YMDTHMS_STRING);
			allocateproductactivitystockBean.setEndTime(EndTime);
			allocateproductactivitystockBean.setActivityID(activityId);
			allocateproductactivitystockBean.setProductActivityId(Integer.valueOf(aids.get(0)));
			allocateproductactivitystockBean.setUserID(sellerId);
			allocateproductactivitystockBean.setProductID(productId);
			allocateproductactivitystockBean.setStoreType(-1);
			
			ProductActivityStockDto productActivityStockDto = new ProductActivityStockDto();
			productActivityStockDto.setActivityPrice(new BigDecimal(10));
			productActivityStockDto.setCatalogId(catalogs.get(0));
			productActivityStockDto.setSku(null);
			productActivityStockDto.setStock(200);
			ProductActivityStock.add(productActivityStockDto);
			allocateproductactivitystockBean.setFBXCatalogLockList(ProductActivityStock);
			
			allocateproductactivitystockCall.setData(allocateproductactivitystockBean);
			allocateproductactivitystockCall.callService();		
			//Logger.debug(allocateproductactivitystockCall.getStatusCode());
			String Code = allocateproductactivitystockCall.getString("Code");
			Logger.verifyEquals("200",Code,"验证Code");
			allocateproductactivitystockCall.getModifyResultList().forEach(pp->{
				Logger.verifyEquals(productId, pp.getProductId(), "验证商品编号");
				Logger.verifyEquals(catalogs.get(0), pp.getCatalogId(), "验证规格编号");
				Logger.verifyEquals(activityId, pp.getActivityID(), "验证活动编号");
				Logger.verifyEquals(aids.get(0), pp.getProductActivityId().toString(), "验证商品在活动中编号");
			});
			//商品规格库存
			/**
			 * catalogNum:创建商品时的规格库存
			 * productActivityStockDto.getStock()：传入的活动库存
			 * istocknum：报名时活动库存的初始值
			 */
			Integer num = catalogNum-productActivityStockDto.getStock()-istocknum;
			Integer inum = new YmtCatalogsIWapper().selectCatalogsByCatalogId(catalogs.get(0)).getiNum();
			Logger.verifyEquals(num,inum,"验证商品库存表与预期期望一致");
			
			//商品活动库存
			Integer num1 = productActivityStockDto.getStock()+istocknum;
			YmtProductActivityStock catalogId = new YmtProductActivityStockWapper().selectByCatalogId(catalogs.get(0));
			Logger.verifyEquals(num1,catalogId.getIstocknum(), "验证商品活动库存表与预期期望一致");
			
			//发送同步指令SyncActivityProduct
			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_AllocateProductActivityStock_004() {
		Logger.start(true,"活动商品，不同规格调拨活动仓库，扣规格库存");
		try {
			/**
			 * 通过
			 */
			//创建商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			//报名活动  获得商品在活动中的id
			/**
			 * 报名接口
			 */
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,"10");
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);
			Logger.debug("活动库存1:"+FormatUtil.beanToGSONString(new YmtProductActivityStockWapper().selectByCatalogId(catalogs.get(0))));
			Integer istocknum = new YmtProductActivityStockWapper().selectByCatalogId(catalogs.get(0)).getIstocknum();
			//活动未开始
			String BeginTime = YMTDateUtil.getBeforeOrNextDay(-1, YMTDateUtil.YMDTHMS_STRING);
			allocateproductactivitystockBean.setBeginTime(BeginTime);
			String EndTime = YMTDateUtil.getBeforeOrNextDay(1, YMTDateUtil.YMDTHMS_STRING);
			allocateproductactivitystockBean.setEndTime(EndTime);
			allocateproductactivitystockBean.setActivityID(activityId);
			allocateproductactivitystockBean.setProductActivityId(Integer.valueOf(aids.get(0)));
			allocateproductactivitystockBean.setUserID(sellerId);
			allocateproductactivitystockBean.setProductID(productId);
			allocateproductactivitystockBean.setStoreType(-1);
			
			ProductActivityStockDto productActivityStockDto1 = new ProductActivityStockDto();
			productActivityStockDto1.setActivityPrice(new BigDecimal(10));
			productActivityStockDto1.setCatalogId(catalogs.get(0));
			productActivityStockDto1.setSku(null);
			productActivityStockDto1.setStock(200);
			ProductActivityStockDto productActivityStockDto2 = new ProductActivityStockDto();
			productActivityStockDto2.setActivityPrice(new BigDecimal(10));
			productActivityStockDto2.setCatalogId(catalogs.get(1));
			productActivityStockDto2.setSku(null);
			productActivityStockDto2.setStock(200);
			ProductActivityStock.add(productActivityStockDto1);
			ProductActivityStock.add(productActivityStockDto2);
			allocateproductactivitystockBean.setFBXCatalogLockList(ProductActivityStock);
			
			allocateproductactivitystockCall.setData(allocateproductactivitystockBean);
			allocateproductactivitystockCall.callService();		
			String Code = allocateproductactivitystockCall.getString("Code");
			Logger.verifyEquals("200",Code,"验证Code");
			ModifyResult modifyResult1 = allocateproductactivitystockCall.getModifyResultList().get(0);
			Logger.verifyEquals(productId, modifyResult1.getProductId(), "验证商品编号");
			Logger.verifyEquals(catalogs.get(0), modifyResult1.getCatalogId(), "验证规格编号");
			Logger.verifyEquals(activityId, modifyResult1.getActivityID(), "验证活动编号");
			Logger.verifyEquals(aids.get(0), modifyResult1.getProductActivityId().toString(), "验证商品在活动中编号");
			ModifyResult modifyResult2 = allocateproductactivitystockCall.getModifyResultList().get(1);
			Logger.verifyEquals(productId, modifyResult2.getProductId(), "验证商品编号");
			Logger.verifyEquals(catalogs.get(1), modifyResult2.getCatalogId(), "验证规格编号");
			Logger.verifyEquals(activityId, modifyResult2.getActivityID(), "验证活动编号");
			Logger.verifyEquals(aids.get(0), modifyResult2.getProductActivityId().toString(), "验证商品在活动中编号");
			//商品规格库存
			/**
			 * catalogNum:创建商品时的规格库存
			 * productActivityStockDto.getStock()：传入的活动库存
			 * istocknum：报名时活动库存的初始值
			 */
			//参加活动规格库存
			Integer num = catalogNum-productActivityStockDto1.getStock()-istocknum;
			Integer inum = new YmtCatalogsIWapper().selectCatalogsByCatalogId(catalogs.get(0)).getiNum();
			Logger.verifyEquals(num,inum,"验证商品库存表与预期期望一致");
			
			Integer num1 = catalogNum-productActivityStockDto2.getStock()-istocknum;
			Integer inum1 = new YmtCatalogsIWapper().selectCatalogsByCatalogId(catalogs.get(1)).getiNum();
			Logger.verifyEquals(num1,inum1,"验证商品库存表与预期期望一致");
			
			//参加规格商品活动库存
			Integer actnum1 = productActivityStockDto1.getStock()+istocknum;
			Integer actinum1 = new YmtProductActivityStockWapper().selectByCatalogId(catalogs.get(0)).getIstocknum();
			Logger.verifyEquals(actnum1,actinum1, "验证商品活动库存表与预期期望一致");
			
			Integer actnum2 = productActivityStockDto2.getStock()+istocknum;
			Integer actinum2 = new YmtProductActivityStockWapper().selectByCatalogId(catalogs.get(1)).getIstocknum();
			Logger.verifyEquals(actnum2,actinum2, "验证商品活动库存表与预期期望一致");
			
			//发送同步指令SyncActivityProduct
			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_AllocateProductActivityStock_005() {
		Logger.start(true,"传库存参数为负数时");
		/**
		 * stock must bigger than 0"
		 */
		try {
			//创建商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,"10");
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);
			//活动未开始
			String BeginTime = YMTDateUtil.getBeforeOrNextDay(-1, YMTDateUtil.YMDTHMS_STRING);
			allocateproductactivitystockBean.setBeginTime(BeginTime);
			String EndTime = YMTDateUtil.getBeforeOrNextDay(1, YMTDateUtil.YMDTHMS_STRING);
			allocateproductactivitystockBean.setEndTime(EndTime);
			allocateproductactivitystockBean.setActivityID(activityId);
			allocateproductactivitystockBean.setProductActivityId(Integer.valueOf(aids.get(0)));
			allocateproductactivitystockBean.setUserID(sellerId);
			allocateproductactivitystockBean.setProductID(productId);
			allocateproductactivitystockBean.setStoreType(-1);
			
			ProductActivityStockDto productActivityStockDto = new ProductActivityStockDto();
			productActivityStockDto.setActivityPrice(new BigDecimal(10));
			productActivityStockDto.setCatalogId(catalogs.get(0));
			productActivityStockDto.setSku(null);
			//不传或者传入的库存参数为负数时
			productActivityStockDto.setStock(-1);
			ProductActivityStock.add(productActivityStockDto);
			allocateproductactivitystockBean.setFBXCatalogLockList(ProductActivityStock);
			
			allocateproductactivitystockCall.setData(allocateproductactivitystockBean);
			allocateproductactivitystockCall.callService();		
			String Code = allocateproductactivitystockCall.getString("Code");
			Logger.verifyEquals("201",Code,"验证Code");
			//发送同步指令SyncActivityProduct
			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_AllocateProductActivityStock_006() {
		Logger.start(true,"不传库存参数时");
		/**
		 * 活动库存表和规格库存表不变
		 */
		try {
			//创建商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,"10");
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);
			Integer istocknum = new YmtProductActivityStockWapper().selectByCatalogId(catalogs.get(0)).getIstocknum();
			//活动未开始
			String BeginTime = YMTDateUtil.getBeforeOrNextDay(-1, YMTDateUtil.YMDTHMS_STRING);
			allocateproductactivitystockBean.setBeginTime(BeginTime);
			String EndTime = YMTDateUtil.getBeforeOrNextDay(1, YMTDateUtil.YMDTHMS_STRING);
			allocateproductactivitystockBean.setEndTime(EndTime);
			allocateproductactivitystockBean.setActivityID(activityId);
			allocateproductactivitystockBean.setProductActivityId(Integer.valueOf(aids.get(0)));
			allocateproductactivitystockBean.setUserID(sellerId);
			allocateproductactivitystockBean.setProductID(productId);
			allocateproductactivitystockBean.setStoreType(-1);
			
			ProductActivityStockDto productActivityStockDto = new ProductActivityStockDto();
			productActivityStockDto.setActivityPrice(new BigDecimal(10));
			productActivityStockDto.setCatalogId(catalogs.get(0));
			productActivityStockDto.setSku(null);
			//不传库存参数
			//productActivityStockDto.setStock(100);
			ProductActivityStock.add(productActivityStockDto);
			allocateproductactivitystockBean.setFBXCatalogLockList(ProductActivityStock);
			
			allocateproductactivitystockCall.setData(allocateproductactivitystockBean);
			allocateproductactivitystockCall.callService();		
			String Code = allocateproductactivitystockCall.getString("Code");
			Logger.verifyEquals("200",Code,"验证Code");
			ModifyResult modifyResult1 = allocateproductactivitystockCall.getModifyResultList().get(0);
			Logger.verifyEquals(productId, modifyResult1.getProductId(), "验证商品编号");
			Logger.verifyEquals(catalogs.get(0), modifyResult1.getCatalogId(), "验证规格编号");
			Logger.verifyEquals(activityId, modifyResult1.getActivityID(), "验证活动编号");
			Logger.verifyEquals(aids.get(0), modifyResult1.getProductActivityId().toString(), "验证商品在活动中编号");
			//参加活动规格库存
			Integer num = catalogNum-istocknum;
			Integer inum = new YmtCatalogsIWapper().selectCatalogsByCatalogId(catalogs.get(0)).getiNum();
			Logger.verifyEquals(num,inum,"验证商品库存表与预期期望一致");
			
			//参加规格商品活动库存
			Integer actinum1 = new YmtProductActivityStockWapper().selectByCatalogId(catalogs.get(0)).getIstocknum();
			Logger.verifyEquals(istocknum,actinum1, "验证商品活动库存表与预期期望一致");
			
			//发送同步指令SyncActivityProduct
			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});		

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_AllocateProductActivityStock_007() {
		Logger.start(true,"活动商品规格，调拨活动库存，扣规格库存  查询redis");
		try {
			//创建商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			System.out.println(catalogs.toString());
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,"10");
			//添加秒杀商品数据
			ProductManagerCallServiceV2.addSecKillStock(activityId,productId, sellerId, true);
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);
			
			Logger.debug("活动库存1:"+FormatUtil.beanToGSONString(new YmtProductActivityStockWapper().selectByCatalogId(catalogs.get(0))));
			Integer istocknum = new YmtProductActivityStockWapper().selectByCatalogId(catalogs.get(0)).getIstocknum();
			//活动未开始
			String BeginTime = YMTDateUtil.getBeforeOrNextDay(-1, YMTDateUtil.YMDTHMS_STRING);
			allocateproductactivitystockBean.setBeginTime(BeginTime);
			String EndTime = YMTDateUtil.getBeforeOrNextDay(2, YMTDateUtil.YMDTHMS_STRING);
			allocateproductactivitystockBean.setEndTime(EndTime);
			allocateproductactivitystockBean.setActivityID(activityId);
			allocateproductactivitystockBean.setProductActivityId(Integer.valueOf(aids.get(0)));
			allocateproductactivitystockBean.setUserID(sellerId);
			allocateproductactivitystockBean.setProductID(productId);
			allocateproductactivitystockBean.setStoreType(-1);
			allocateproductactivitystockBean.setIsFbxProduct(true);
			
			ProductActivityStockDto productActivityStockDto = new ProductActivityStockDto();
			productActivityStockDto.setActivityPrice(new BigDecimal(10));
			productActivityStockDto.setCatalogId(catalogs.get(0));
			productActivityStockDto.setSku(null);
			productActivityStockDto.setStock(10);
			ProductActivityStock.add(productActivityStockDto);

			allocateproductactivitystockBean.setFBXCatalogLockList(ProductActivityStock);
			
			allocateproductactivitystockCall.setData(allocateproductactivitystockBean);
			allocateproductactivitystockCall.callService();		
			//Logger.debug(allocateproductactivitystockCall.getStatusCode());
			
			String Code = allocateproductactivitystockCall.getString("Code");
			Logger.verifyEquals("200",Code,"验证Code");
			allocateproductactivitystockCall.getModifyResultList().forEach(pp->{
				Logger.verifyEquals(productId, pp.getProductId(), "验证商品编号");
				Logger.verifyEquals(catalogs.get(0), pp.getCatalogId(), "验证规格编号");
				Logger.verifyEquals(activityId, pp.getActivityID(), "验证活动编号");
				Logger.verifyEquals(aids.get(0), pp.getProductActivityId().toString(), "验证商品在活动中编号");
			});
			//商品规格库存
			/**
			 * catalogNum:创建商品时的规格库存
			 * productActivityStockDto.getStock()：传入的活动库存
			 * istocknum：报名时活动库存的初始值
			 */
			Integer num = catalogNum-productActivityStockDto.getStock()-istocknum;
			Integer inum = new YmtCatalogsIWapper().selectCatalogsByCatalogId(catalogs.get(0)).getiNum();
			Logger.verifyEquals(num,inum,"验证商品库存表与预期期望一致");
			
			//商品活动库存
			Integer num1 = productActivityStockDto.getStock()+istocknum;
			YmtProductActivityStock catalogId = new YmtProductActivityStockWapper().selectByCatalogId(catalogs.get(0));
			Logger.verifyEquals(num1,catalogId.getIstocknum(), "验证商品活动库存表与预期期望一致");
			
			//发送同步指令SyncActivityProduct
			MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
			
			
			RedisDriver rd = new RedisDriver("group1",EnvSetup.getSystemUrl("sentinel"));
			String key="SecStock:"+aids.get(0)+":"+catalogs.get(0);
			Logger.comment("获取redis，key为："+key+"值为："+rd.getValue(key));
			Logger.verifyEquals(rd.getValue(key),num1+"", "验证redis库存");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	
	
}